package com.wyy.multiredis;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @Date: 2023/12/13
 * @Author: wyy
 */
public class RedisTemplateFactory implements FactoryBean<RedisTemplate> {

    private RedisConnectionFactory connectionFactory;

    public RedisTemplateFactory(RedisConnectionFactory connectionFactory) {
        this.connectionFactory = connectionFactory;
    }

    @Override
    public RedisTemplate getObject() throws Exception {
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(connectionFactory);
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }

    @Override
    public Class<?> getObjectType() {
        return RedisTemplate.class;
    }
}
